<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CursosController
 *
 * @author MFerreira
 * @export Modules
 * @export-metadata category:Cursos:Horario de clases
 * @export-metadata RequiredRoles:ROLE_STUDENT
 */

class Horario extends Module {


    public function index() {

        $periodo = $this->model->students->GetLastPeriodoMatriculado($this->currentUser->getName());
        $Cursos = $this->model->courses->GetByEstudianteAndPeriodoAcademico($this->currentUser->getName(), $periodo);

        $this->assign("Horario", $this->InitializeSchedule($Cursos));
        $this->assign("Dias", array("Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"));
        $this->assign("action", $this->route->action("index"));
        $this->display();
    }

    private function InitializeSchedule($Cursos) {
        $Arreglo = array();

        for ($i = 1; $i < 7; $i++) {
            $Semana = array();
            foreach ($Cursos as $key => $Curso) {
                foreach ($Curso->getListaHorariosCursos() as $key => $Horario) {
                    if ($Horario->getHorarioCursoPk()->getDia() == $i) {
                        $Semana[] = array(
                            "Materia" => $Curso->getMateria()->getNombreMateria(),
                            "Grupo" => $Curso->getCursoPk()->getGrupo(),
                            "CodigoMateria" => $Curso->getCursoPk()->getCodigoMateria(),
                            "HoraInicio" => $Horario->getHorario()->getHoraInicial(),
                            "HoraFin" => $Horario->getHorario()->getHoraFinal()
                        );
                    }
                }
            }
            $Arreglo[] = $Semana;
        }
        
        return $Arreglo;
    }

}

?>
